const urlStr = 'www.baidu.com?name=ck&age=10&hobbies=basketball&name=bob&name=cookie'

function queryParams(urlStr) {
    const keyValArr = urlStr.split('?')[1].split('&')
    // console.log(keyValArr)
    const paramObj = {}
    keyValArr.map(item => {
        const KV = item.split('=')
        paramObj[KV[0]] = KV[1]
    })
    return paramObj;
}

const getPargams = (urlStr) => {
  let resTxt = "";
  const res = urlStr
    .split("?")[1]
    .split("&")
    // .map((item) => ({ [item.split("=")[0]]: item.split("=")[1] }))
    .map((item) => {
      if (item.split("=")[0] === "name") {
        resTxt = item.split("=")[1];
      }
    });
  console.log(resTxt);
  return res;
};

getPargams(urlStr);

// console.log(queryParams(urlStr));


// function getUrlParams(url) {
//     let result = []
//     let tag = []

//     url = JSON.parse(JSON.stringify(url))
//     const keyValue = url.split('?')[1].split('&')


//     keyValue.map(item => {
//         const [key, value] = item.split('=')
//         if (tag.includes(key)) {
//             const index = tag.indexOf(key)
//             result[index].value ?
//                 (result[index].value = Array.isArray(result[index].value) ? [...result[index].value, value] : [result[index].value, value]) : result[index].value = value
//         } else {
//             tag.push(key)
//             result.push({key, value})
//         }
//     })
//     console.log(result)
// }


// getUrlParams(urlStr)
